package com.xiang;

import com.alibaba.ttl.TransmittableThreadLocal;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TransmittableThreadLocalMain {
    static TransmittableThreadLocal<String> context = new TransmittableThreadLocal<>();

    public static void main(String[] args) {
        // 在父线程中设置
        context.set("value-set-in-parent");

        new Thread(()->{
            // 在子线程中可以读取，值是"value-set-in-parent"
            String value = context.get();
            log.info("value: {}" ,value);

        },"Thread--").start();

    }
}
